import yaml

import conf.settings
from LogHandler import logger


class YamlHandler(object):
    def read_yaml(self, file_path):
        try:
            logger.info("正在读取Yaml文件")
            with open(file_path, mode='r', encoding='utf-8') as f:
                data = yaml.full_load(f)
                logger.info("读取Yaml文件成功")
                return data
        except Exception as e:
            logger.info(f"读取Yaml文件失败：{e}")

    def write_yaml(self, file_path, data):
        try:
            with open(file_path, mode='w', encoding='utf-8') as f:
                yaml.dump(data, stream=f, Dumper=yaml.SafeDumper, allow_unicode=True)
                logger.info("写入Yaml文件成功")
        except Exception as e:
            logger.info(f"写入Yaml文件失败：{e}")


yamler = YamlHandler()
